package com.example.fragmentbrowser

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment

class MyFragment : Fragment() {

    companion object {
        private const val ARG_SECTION_NUMBER = "section_number"

        // 创建新实例的工厂方法，可传递参数
        fun newInstance(sectionNumber: Int): MyFragment {
            return MyFragment().apply {
                arguments = Bundle().apply {
                    putInt(ARG_SECTION_NUMBER, sectionNumber)
                }
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        val view = inflater.inflate(R.layout.fragment_my, container, false)

        val sectionNumber = arguments?.getInt(ARG_SECTION_NUMBER) ?: 0
        val textView: TextView = view.findViewById(R.id.section_label)
        textView.text = getString(R.string.section_format, sectionNumber)

        return view
    }
}